#override("css")
<link href="#springUrl('/static/plugins/zTree/css/metroStyle/metroStyle.css')" rel="stylesheet">
<link href="#springUrl('/static/css/plugins/bootstrap-table/bootstrap-table.min.css')" rel="stylesheet">
#end

#override("body")
<body class="white-bg">
<div class="wrapper wrapper-content">
	<div class="panel panel-default">
		<div class="row">
			<div class="col-xs-3">
				<div class="ibox-content text-right" style="background: #F3F3F4;">
					<div class="row">
						<div class="col-md-12">
							<div class="ibox float-e-margins">
								<div class="ibox-content">
									<div class="form-group">
										<ul id="treeDemo" class="ztree"></ul>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="col-xs-9">
				<div class="ibox-content" style="background: #F3F3F4;">
					<div class="row text-right form-inline">
						<div class="col-sm-12">
							<input type="hidden" name="orgNo" value="$!{orgNo}">

							#if ($SSOPermission.isActionable("param:sysUser:list"))
							<div class="input-group">
								<input type="text" class="form-control">
								<span class="input-group-btn">
										<button type="button" class="btn btn-info" id="searchId">搜索</button>
									</span>
							</div>
							#end
							#if ($SSOPermission.isActionable("param:sysUser:add"))
							<button type="button" class="btn btn-primary" id="addId">
								<i class="fa fa-pencil"></i>&nbsp;添加
							</button>
							#end
						</div>
					</div>
					<br />
					<div class="row">
						<div class="col-sm-12">
							<div class="ibox float-e-margins">
								<div class="ibox-content">
									<table id="dataTable"></table>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
#end

#override("js")
<script src="#springUrl('/static/js/plugins/bootstrap-table/bootstrap-table.min.js')"></script>
<script src="#springUrl('/static/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js')"></script>
<script src="#springUrl('/static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js')"></script>
<script src="#springUrl('/static/js/bank/base_list.js')"></script>
<script type="text/javascript">
	var dataUrl = "#springUrl('/sys/sysUser/listJson.html')";
	var dataColumns = [{
		field: 'xh',
		title: '序号',
		width: '20px',
		formatter: function (value, row, index) {
			return index + 1;
		}
	}, {
		field: 'id',
		title: '主键ID',
		visible : false
	}, {
		field: 'userCode',
		title: '用户编号'
	}, {
		field: 'mainCorpNo',
		title: '核心客户号'
	}, {
		field: 'userName',
		title: '用户名'
	}, {
		field: 'orgNo',
		title: '所属机构'
	}, {
		field: 'sex',
		title: '性别',
		formatter: function (value) {
		if (value == 0) return "男";
		else if (value == 1) return "女";
	}
	}, {
		field: 'loginDate',
		title: '最后登陆时间',
		formatter: function(value) {
			return formatDate(value);
		}
	}, {
		field: 'state',
		title: '状态',
		formatter: function (value, row, index) {
			if (value == 0) return "正常";
			else if (value == 1) return "禁用";
		}
	}, {
		title: '操作',
		formatter: function (value, row, index) {
			var id = row.id;
			var button = '';

			// 此处按钮级别权限控制，目前只有 admin 拥有该权限
			#if ($SSOPermission.isActionable("param:sysUser:view"))
				button += '<a class="btn btn-xs btn-primary" onclick="toView(' + "'" + id + "'" + ')"><i class="fa fa-remove"></i>查看</a> '
			#end;
			#if ($SSOPermission.isActionable("param:sysUser:edit"))
				button += '<a class="btn btn-xs btn-info" onclick="toEdit(' + "'" + id + "'" + ')"><i class="fa fa-pencil"></i>编辑</a> '
			#end;
			#if ($SSOPermission.isActionable("param:sysUser:delete"))
				button += '<a class="btn btn-xs btn-danger" onclick="doDel(' + "'" + id + "'" + ')"><i class="fa fa-remove"></i>删除</a> '
			#end;
			#if ($SSOPermission.isActionable("param:sysUser:allot"))
				button += '<a class="btn btn-xs btn-success" onclick="allot(' + "'" + id + "'" + ')"><i class="fa fa-edit"></i>分配角色</a>';
			#end
			return button;
		}
	}];

	function dataQueryParams(params) {
		return {
			_size: params.limit, 			// 页面大小
			_index: params.offset, 			// 页码
			orgNo : $("input[name='orgNo']").val()
		};
	}

	$('#searchId').click(function() {
		refreshTable();
	});

	function refreshTable() {
		$('#dataTable').bootstrapTable('refresh');
	}
</script>
<script type="text/javascript">
	var v_title; 						// 弹出窗标题
	var url;  							// 请求/跳转URL

	/** 新增 */
	$('#addId').click(function() {
		v_title = "新增";
		url = "#springUrl('/sys/sysUser/toEdit/0')";

		var buttons = ['保存', '取消'];
		var functions = {
			yes: saveBaseInfo,
			cancel: function () {}
		};
		popWindow(v_title, url, buttons, functions);
	});

	/** 查看详情 */
	function toView(id) {
		v_title = "查看";
		url = "#springUrl('/sys/sysUser/toView/')" + id;

		var buttons = [ '返回'];
		var functions = {
			cancel : function() {
			}
		};
		popWindow(v_title, url, buttons, functions);
	}

	/** 编辑/修改/重新编辑 */
	function toEdit(id) {
		v_title = "修改";
		url = "#springUrl('/sys/sysUser/toEdit/')" + id;

		var buttons = [ '保存', '取消'];
		var functions = {
			yes : saveBaseInfo,
			cancel : function() {
			}
		};
		popWindow(v_title, url, buttons, functions);
	}

	/** 将信息删除 */
	function doDel(ids) {
		// 多选删除
		if(isNull(ids)) {
			ids = "";
			var rows = $("#dataTable").bootstrapTable("getSelections");
			if (rows.length == 0) {
				layer.msg("请选择一行进行操作!");
				return;
			}
			for (var i = 0; i < rows.length; i++) {
				ids += rows[i].id + ",";
			}
			if (ids.charAt(ids.length - 1) == ",") {
				ids = ids.substring(0, ids.lastIndexOf(","));
			}
		}
		layer.confirm('确定删除?', {
			btn: ['确定', '取消'] // 按钮
		}, function () {
			$.ajax({
				url: "#springUrl('/sys/sysUser/doDelete/')" + ids,
				timeout: 1000,
				async: true,
				error: function () {
					layer.msg("删除失败!", {icon: 2});
				},
				success: function (data) {
					if (data.success) {
						layer.alert('删除成功', {icon: 1});
						refreshTable();
					} else {
						layer.alert(data.message, {icon: 2});
					}
				}
			});
		});
	}
</script>
<script type="text/javascript">
	//保存基本信息回调
	function saveBaseInfo(index, layero) {
		var v_index = layer.load(0, { shade: 0.2 });
		//调用iframe中的js方法
		getIframe(layero).save();// 保存信息
		layer.close(v_index);
	}
</script>

<!-- 与左边树有关的JS -->
<script type="text/javascript">
	var data = $!{orgs};
	var settings = {
		check: {
			enable: true,
			chkStyle: "radio",
			radioType: "all",
			selectedMulti: false
		},
		view: {
			dblClickExpand: false
		},
		data: {
			key: {
				name: 'name'
			},
			simpleData: {
				enable: true,
				idKey: 'id',
				pIdKey: 'pId',
				rootPId: ""
			}
		},
		callback: {
			onClick: onClick,
			onCheck: onCheck
		}
	}

	function onClick(e, treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		if (treeNode.parentT)
			zTree.checkNode(treeNode, treeNode.checked, null, true);

		// 当前点击的节点
		$("input[name='orgNo']").val(treeNode.id);
		refreshTable();
	}

	function onCheck(e, treeId, treeNode) {
		// 当前点击的节点
		$("input[name='orgNo']").val(treeNode.id);
		refreshTable();
	}

	$(function () {
		$.fn.zTree.init($("#treeDemo"), settings, data);
		var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		var nodes = treeObj.getNodes();
		// 设置节点展开(默认展开三级)
		for (var i = 0; i < nodes.length; i++) {
			treeObj.expandNode(nodes[i], true, false, true);
			if (nodes[i].isParent) {
				var sNodes = nodes[i].children;
				for (var j = 0; j < sNodes.length; j++) {
					treeObj.expandNode(sNodes[j], true, false, true);

					if (sNodes[j].isParent) {
						var kNodes = sNodes[i].children;
						for (var k = 0; k < kNodes.length; k++) {
							treeObj.expandNode(kNodes[k], true, false, true);
						}
					}
				}
			}
		}
	});
</script>

<!-- 给用户分配角色 -->
<script type="text/javascript">
	function allot(id) {
		var title = "分配角色";
		var url = "#springUrl('/sys/sysUser/allot/')" + id;
		layer.open({
			type: 2,
			title: title,
			shadeClose: true,
			shade: 0.8,
			area: ['550px', '430px'],
			fix: false,
			maxmin: true,
			content: url
		});
	}
</script>
#end
#extends("/common/base.html")